package com.clementheliou.cheliou.business.technical.security.authentication.model;

import java.awt.Dimension;
import java.util.ArrayList;
import java.util.Collection;

import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import com.clementheliou.cheliou.dal.model.member.enumeration.MemberLocale;

/**
 * Core information about the user to be authenticated. After the
 * authentication, this object will be used to retrieved uncritical data about
 * user such as email, name or first name.
 * 
 * @author Clément HELIOU (clement.heliou@gmail.com)
 * @see {@link UserDetails}.
 * @since 1.0
 */
public class AuthenticationDetails implements UserDetails {

	/**
	 * UID for serialization.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private static final long serialVersionUID = 7753521991895694271L;

	/**
	 * Flag indicating if the account is expired or not.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private boolean accountNonExpired;

	/**
	 * Flag indicating if the account is locked or not.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private boolean accountNonLocked;

	/**
	 * Flag indicating if the account credentials are expired or not.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private boolean credentialsNonExpired;

	/**
	 * Flag indicating if the account is enabled or not.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private boolean enabled;

	/**
	 * Roles granted to the user.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @see {@link GrantedAuthority}.
	 * @since 1.0
	 */
	private Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();

	/**
	 * The user's screen size.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private Dimension screenSize;

	/**
	 * The user language.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @see {@link MemberLocale}.
	 * @since 1.0
	 */
	private MemberLocale memberLocale;

	/**
	 * The user's technical identifier.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private Integer memberId;

	/**
	 * The user password. Please note that this field should be empty after the
	 * authentication. It shouldn't be accessible during the session.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private String password;

	/**
	 * The user first name.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private String firstName;

	/**
	 * The user name (in fact, its email).
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private String username;

	/**
	 * The user name.
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	private String name;

	/*
	 * Getters & setters.
	 */

	/**
	 * {@inheritDoc}
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	@Override
	public Collection<GrantedAuthority> getAuthorities() {
		return authorities;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	@Override
	public String getPassword() {
		return password;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	@Override
	public String getUsername() {
		return username;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	@Override
	public boolean isAccountNonExpired() {
		return accountNonExpired;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	@Override
	public boolean isAccountNonLocked() {
		return accountNonLocked;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	@Override
	public boolean isCredentialsNonExpired() {
		return credentialsNonExpired;
	}

	/**
	 * {@inheritDoc}
	 * 
	 * @author Clément HELIOU (clement.heliou@gmail.com)
	 * @since 1.0
	 */
	@Override
	public boolean isEnabled() {
		return enabled;
	}

	public void setAccountNonExpired(boolean accountNonExpired) {
		this.accountNonExpired = accountNonExpired;
	}

	public void setAccountNonLocked(boolean accountNonLocked) {
		this.accountNonLocked = accountNonLocked;
	}

	public void setCredentialsNonExpired(boolean credentialsNonExpired) {
		this.credentialsNonExpired = credentialsNonExpired;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}

	public void setAuthorities(Collection<GrantedAuthority> authorities) {
		this.authorities = authorities;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public MemberLocale getMemberLocale() {
		return memberLocale;
	}

	public void setMemberLocale(MemberLocale memberLocale) {
		this.memberLocale = memberLocale;
	}

	public Integer getMemberId() {
		return memberId;
	}

	public void setMemberId(Integer memberId) {
		this.memberId = memberId;
	}

	public Dimension getScreenSize() {
		return screenSize;
	}

	public void setScreenSize(Dimension screenSize) {
		this.screenSize = screenSize;
	}

}
